package com.xuecheng.content.api;

import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("/courseTeacher")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    /**
     * 根据课程id查该课程所有教师
     * @param id
     * @return
     */
    @GetMapping("/list/{id}")
    public List<CourseTeacher> list(@PathVariable Long id){
        return courseTeacherService.listTeacher(id);
    }

    /**
     * 添加或修改教师信息
     * @param courseTeacher
     */
    @PostMapping
    public CourseTeacher savaTeacher(@RequestBody CourseTeacher courseTeacher){
        return courseTeacherService.saveTeacher(courseTeacher);
    }


    /**
     * 根据课程id和对应教师id删除
     * @param courseId
     * @param courseTeacherId
     */
    @DeleteMapping("/course/{courseId}/{courseTeacherId}")
    public void deleteCourseTeacher(@PathVariable Long courseId,@PathVariable Long courseTeacherId){
        courseTeacherService.deleteCourseTeacher(courseId,courseTeacherId);
    }
}
